Fix cache hash for user-defined record types#7184
Closed
jorgee wants to merge 1 commit into
Closed
Conversation
Typed records (declared via `record … { … }`) instantiated by their
generated constructor fell through the type dispatch in `HashBuilder`
to the catch-all that uses `value.hashCode()`. Because the generated
record classes don't override `hashCode`, every instance produced a
different identity-based hash and `-resume` always re-ran the task.
This adds a `Record` branch that reflectively extracts a record's
public, non-static fields into a map and hashes it through the same
unordered-collection path used by `Map`/`RecordMap`. As a result,
records built via the `record(...)` built-in and records instantiated
from a typed declaration produce the same hash when their field values
are equal, regardless of insertion order or JVM identity.
Signed-off-by: Jorge Ejarque <jorge.ejarque@seqera.io>
Signed-off-by: jorgee <jorge.ejarque@seqera.io>
✅ Deploy Preview for nextflow-docs-staging canceled.
|
bentsherman
reviewed
May 28, 2026
Comment on lines
+159
to
+160
| else if( value instanceof Record ) | ||
| hashUnorderedCollection(hasher, recordToMap((Record) value).entrySet(), mode); |
Member
There was a problem hiding this comment.
Every record instance is a RecordMap, so it should be caught by the Map case above
bentsherman
reviewed
May 28, 2026
Comment on lines
+178
to
+181
| def r1 = new SampleRecord('alpha', 1) | ||
| def r2 = new SampleRecord('alpha', 1) | ||
| def r3 = new SampleRecord('beta', 1) | ||
| def r4 = new SampleRecord('alpha', 2) |
Member
There was a problem hiding this comment.
Records cannot be created via constructor. But it may be that this happens to work and is only disallowed by the type checker
Member
|
Closing in favor of #7185 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Typed records — those declared via
record … { … }and instantiated through their generated constructor — fell through the type dispatch inHashBuilderto the catch-all that usesvalue.hashCode(). Because the generated record classes don't overridehashCode, every instance produced a different identity-based hash, and-resumealways re-ran the task even when inputs were equal.The user-visible symptom in
-dump-hashesis a record value rendered as_nf_script_xxx.Dataset@20d692ba(the JVM defaultObject.toString()), with a different@<hex>suffix on every run.This PR adds a
Recordbranch toHashBuilder.with(Object)that reflectively reads the record's public, non-static instance fields into aLinkedHashMap<String,Object>and hashes it through the samehashUnorderedCollectionpath used forMap/RecordMap. Net effects:-resumeworks.record(...)stdlib helper and a typed-record constructor with the same field values produce the same hash.Mapbranch soRecordMap(which is bothRecordandMap) keeps its existing hashing path.Test plan
New unit tests in
HashBuilderTest:should hash typed record by field values, independent of JVM identity— regression test for the-resumebug.typed record and equivalent RecordMap should hash to the same valuerecord built with the record(...) built-in should hash the same as the typed constructorrecord(...) built-in hash should not depend on the order of named argumentsnested typed records should hash by value— recursion through the new branch.nested typed record and nested RecordMap should hash equally./gradlew :nf-commons:test --tests "nextflow.util.HashBuilderTest"— 17/17 pass.CacheHelperTest,RecordMapTest,TypeHelperTest— unaffected.🤖 Generated with Claude Code